package com.example.news.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.news.mapper.GoodsTypeMapper;
import com.example.news.pojo.GoodsType;
import com.example.news.service.IGoodsTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class GoodsTypeServiceImpl implements IGoodsTypeService {

    private final GoodsTypeMapper goodsTypeMapper;

    @Override
    public List<GoodsType> queryGoodsType(String name, Integer pageNo, Integer pageSize) {
        LambdaQueryWrapper<GoodsType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(name), GoodsType::getName, name);

        Page<GoodsType> p = new Page<GoodsType>(pageNo, pageSize);

        Page pageResult = goodsTypeMapper.selectPage(p, queryWrapper);

        return pageResult.getRecords();
    }
}
